<template>
  <div class="product-info">
    <div class="product-header">
      <span class="product-id"
        >商品编号：<span class="product-id-value">{{ orderData.productId || "12345678900987654321" }}</span></span
      >
    </div>

    <div class="product-content">
      <div class="product-image">
        <img :src="orderData.productImage || 'src/assets/temp_product.png'" :alt="orderData.productName" />
      </div>

      <div class="product-details">
        <div class="product-name">
          <div class="name">
            <span class="tags">全新</span>
            <span>&nbsp;&nbsp;</span>
            <span>{{ orderData.productName || "商品名称商品名称商" }}</span>
          </div>
          <span class="quantity">x1</span>
        </div>

        <div class="product-color">
          <span class="label">规格颜色：</span>
          <span class="value">{{ orderData.productColor || "群青色/512GB" }}</span>
        </div>

        <div class="accessories" @click="showAccessoriesDialog = true">
          <span class="label">配件清单(3) ></span>
        </div>
      </div>
    </div>
    <div class="product-footer">
      <div class="product-footer-row">
        <span class="label">租赁方式：</span>
        <span class="value">{{ orderData.rentalMethod || "租完归还/买断" }}</span>
      </div>

      <div class="product-footer-row">
        <span class="label">租期：</span>
        <span class="value">{{ orderData.rentalPeriod || "2025-03-16至2026-06-13 (共455天)" }}</span>
      </div>
    </div>
    <!-- 配件清单弹窗 -->
    <base-dialog
      v-model="showAccessoriesDialog"
      title="配件清单"
      width="650px"
      :show-footer="false"
      @cancel="handleClose"
    >
      <div class="accessories-content">
        <!-- 赠品 -->
        <div class="accessories-section">
          <div class="section-title">赠品</div>
          <div class="accessories-grid">
            <div v-for="(item, index) in giftAccessories" :key="`gift-${index}`" class="accessory-item">
              <div class="accessory-name">{{ item.name }}</div>
              <div class="accessory-quantity">x{{ item.quantity }}</div>
            </div>
          </div>
        </div>

        <!-- 需归还 -->
        <div class="accessories-section">
          <div class="section-title">需归还</div>
          <div class="accessories-grid">
            <div v-for="(item, index) in returnAccessories" :key="`return-${index}`" class="accessory-item">
              <div class="accessory-name">{{ item.name }}</div>
              <div class="accessory-quantity">x{{ item.quantity }}</div>
            </div>
          </div>
        </div>
      </div>
    </base-dialog>
  </div>
</template>

<script setup>
  import { ref } from "vue";

  defineProps({
    orderData: {
      type: Object,
      required: false,
      default: () => ({}),
    },
  });

  // 弹窗显示状态
  const showAccessoriesDialog = ref(false);

  // 赠品配件数据
  const giftAccessories = ref([
    { name: "壳膜包(保护壳、钢化膜)", quantity: 1 },
    { name: "iCloud+ (50GB)", quantity: 1 },
    { name: "壳膜包(保护壳、钢化膜)\n多行文本", quantity: 1 },
  ]);

  // 需归还配件数据
  const returnAccessories = ref([
    { name: "壳膜包(保护壳、钢化膜)", quantity: 1 },
    { name: "iCloud+ (50GB)", quantity: 1 },
    { name: "壳膜包(保护壳、钢化膜)\n多行名称样式，高度不写死，随内容撑高，数量固定在底部", quantity: 1 },
  ]);

  // 关闭弹窗
  const handleClose = () => {
    showAccessoriesDialog.value = false;
  };
</script>

<style lang="scss" scoped>
  .label {
    color: var(--ct3);
  }

  .value {
    color: var(--ct1);
  }

  :deep(.base-dialog .el-dialog__footer) {
    padding: 12px 0 !important;
  }
  .product-info {
    padding: 10px 12px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    background: linear-gradient(180deg, #f4f3f6 0%, rgba(255, 255, 255, 0) 55.29%);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    .product-header {
      .product-id {
        font-size: 12px;
        color: var(--ct3);
        .product-id-value {
          color: var(--bd);
          cursor: pointer;
        }
      }
    }
    .product-footer {
      border-radius: 4px;
      background-color: var(--fl1);
      padding: 8px 12px;
      font-size: 12px;
      display: flex;
      flex-direction: column;
      gap: 2px;
      .product-footer-row {
        display: flex;
        align-items: center;
      }
    }

    .product-content {
      display: flex;
      gap: 8px;

      .product-image {
        position: relative;
        flex-shrink: 0;

        img {
          width: 100px;
          height: 100px;
          object-fit: cover;
          border-radius: 8px;
          background: var(--bg2);
        }

        .product-condition {
          position: absolute;
          top: 4px;
          left: 4px;
          padding: 2px 6px;
          background: var(--sc);
          color: white;
          font-size: 10px;
          border-radius: 4px;
        }
      }

      .product-details {
        flex: 1;
        display: flex;
        flex-direction: column;
        min-width: 0;
        padding: 4px 0;
        gap: 4px;
        .product-name {
          display: flex;
          align-items: baseline;
          justify-content: space-between;
          gap: 8px;
          margin-bottom: 8px;

          .name {
            font-size: 14px;
            color: var(--ct1);

            .tags {
              border: 1px solid var(--bd8);
              color: var(--bd);
              border-radius: 4px;
              font-size: 12px;
              padding: 0 8px;
              line-height: 20px;
              height: 20px;
            }
          }

          .quantity {
            font-size: 12px;
            color: var(--ct3);
          }
        }

        .product-color,
        .accessories {
          display: flex;
          align-items: center;
          font-size: 12px;
        }

        .accessories {
          .label {
            color: var(--bd);
            cursor: pointer;

            &:hover {
              text-decoration: underline;
            }
          }
        }
      }
    }
  }

  // 配件清单弹窗样式
  .accessories-content {
    .accessories-section {
      margin-bottom: 16px;

      &:last-child {
        margin-bottom: 0;
      }

      .section-title {
        font-size: 16px;
        font-weight: 600;
        color: var(--ct1);
        margin-bottom: 12px;
        padding-left: 8px;
        position: relative;

        &::before {
          content: "";
          position: absolute;
          left: 0;
          top: 50%;
          transform: translateY(-50%);
          width: 3px;
          height: 16px;
          background: var(--bd);
          border-radius: 4px;
        }
      }

      .accessories-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;

        .accessory-item {
          background: var(--fl1);
          border-radius: 8px;
          padding: 10px;
          position: relative;
          min-height: 72px;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          box-sizing: border-box;

          .accessory-name {
            font-size: 14px;
            color: var(--ct1);
            line-height: 22px;
            white-space: pre-line;
            word-break: break-word;
            margin-bottom: 30px;
          }

          .accessory-quantity {
            font-size: 12px;
            color: var(--ct3);
            text-align: center;
            position: absolute;
            bottom: 10px;
            left: 10px;
          }
        }
      }
    }
  }
</style>
